<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/5/24
 * Time: 17:05
 */

namespace Home\Service;


use Common\Common\Service;
use Home\Component\WechatComponent;
use Home\Exception\HomeException;
use Home\Request\wechat\FindWechatRequest;
use Home\Response\FindWechatResponse;

class FindWechatService implements Service
{
    public function run(FindWechatRequest $request = null)
    {
        $openid = $request->getOpenId();
        $component = new WechatComponent();
        $response = new FindWechatResponse();
        try {
            $data = $component->findWechat($openid);
            if (is_null($data)) {
                $response->setItIsNull();
            } else {
                $response->setData($data);
            }
        } catch (HomeException $e) {
            throw new HomeException($e->getMessage(), $e->getCode());
        }
        return $response;
    }
}